#!/usr/bin/env python3
"""
访客相关Pydantic模式
"""

from datetime import datetime

from pydantic import BaseModel, Field


class VisitorBase(BaseModel):
    """访客基础模式"""

    name: str = Field(..., max_length=100, description="访客姓名")
    id_card: str = Field(..., max_length=18, description="身份证号")
    phone: str = Field(..., max_length=20, description="手机号码")
    company: str | None = Field(None, max_length=200, description="所属单位")
    visit_reason: str = Field(..., max_length=500, description="访问事由")
    interviewee: str = Field(..., max_length=100, description="被访人")
    interviewee_department: str = Field(..., max_length=100, description="被访部门")
    planned_visit_time: datetime = Field(..., description="计划访问时间")
    planned_leave_time: datetime | None = Field(None, description="计划离开时间")
    is_special: bool = Field(False, description="是否特殊访客")
    remarks: str | None = Field(None, description="备注信息")


class VisitorCreate(VisitorBase):
    """访客创建模式"""

    pass


class VisitorUpdate(BaseModel):
    """访客更新模式"""

    name: str | None = Field(None, max_length=100, description="访客姓名")
    phone: str | None = Field(None, max_length=20, description="手机号码")
    company: str | None = Field(None, max_length=200, description="所属单位")
    visit_reason: str | None = Field(None, max_length=500, description="访问事由")
    interviewee: str | None = Field(None, max_length=100, description="被访人")
    interviewee_department: str | None = Field(None, max_length=100, description="被访部门")
    planned_visit_time: datetime | None = Field(None, description="计划访问时间")
    planned_leave_time: datetime | None = Field(None, description="计划离开时间")
    actual_visit_time: datetime | None = Field(None, description="实际访问时间")
    actual_leave_time: datetime | None = Field(None, description="实际离开时间")
    status: str | None = Field(
        None, description="状态: pending-待审核, approved-已批准, rejected-已拒绝, visiting-访问中, completed-已完成"
    )
    is_special: bool | None = Field(None, description="是否特殊访客")
    remarks: str | None = Field(None, description="备注信息")


class VisitorResponse(VisitorBase):
    """访客响应模式"""

    id: int
    status: str
    qr_code: str | None
    qr_code_expire_time: datetime | None
    actual_visit_time: datetime | None
    actual_leave_time: datetime | None
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True


class VisitorListResponse(BaseModel):
    """访客列表响应模式"""

    data: list[VisitorResponse]
    total: int
    page: int
    page_size: int
    total_pages: int
